package com.hatic.test;

import java.util.List;
import java.util.Map;

import org.jxstar.dao.DaoParam;
import org.jxstar.service.BusinessObject;
import org.jxstar.util.key.CodeCreator;
import org.jxstar.util.key.KeyCreator;

/**
 * 生成合同文本
 * @author Thinkpad
 *
 */
public class creatContractBO  extends BusinessObject {
	private static final long serialVersionUID = 1L;
	
	public String creatContract(){
		
		List<Map<String, String>> list=queryProject();
		
		for(int i = 0, n = list.size(); i < n; i++){      
			Map<String, String> mpData = list.get(i);
			
			String isql = "insert into contract("+
			"contract_id,contract_code,contract_status,contract_type,"+
			"project_id,project_code,project_name,dept_name,dept_id,project_user,project_userid,money_type,auth_type,"+
			"project_money,done_deptname,done_deptid,"+
			"creat_date,creat_user,contract_money,auditing)"+
			"values(?,?,?,?,"+
			"?,?,?,?,?,?,?,?,?,"+
			"?,?,?,"+
			"?,?,?,?)";
			
			DaoParam iparam = _dao.createParam(isql);
			String contractID = KeyCreator.getInstance().createKey("contract_creat");
			String contractCode = CodeCreator.getInstance().createCode("project_create");
			
			iparam.addStringValue(contractID);
			iparam.addStringValue(contractCode);
			iparam.addStringValue("0");
			iparam.addStringValue("0");
			iparam.addStringValue(mpData.get("project_id"));
			iparam.addStringValue(mpData.get("project_code"));
			iparam.addStringValue(mpData.get("project_name"));
			iparam.addStringValue(mpData.get("dept_name"));
			iparam.addStringValue(mpData.get("dept_id"));
			iparam.addStringValue(mpData.get("project_user"));
			iparam.addStringValue(mpData.get("project_userid"));
			iparam.addStringValue(mpData.get("money_type"));
			iparam.addStringValue(mpData.get("auth_type"));
			iparam.addStringValue(mpData.get("project_money"));
			iparam.addStringValue(mpData.get("done_deptname"));
			iparam.addStringValue(mpData.get("done_deptid"));
			
			iparam.addStringValue("");
			iparam.addStringValue("");
			iparam.addStringValue(mpData.get("project_money"));
			iparam.addStringValue("0");
			
			if (!_dao.update(iparam)) {
				_log.showError("创建合同文本出错！");
				return _returnFaild;
			}
		
		}
		return _returnSuccess;
	}
	
	
	
	//取项目的值
	private List<Map<String,String>> queryProject() {
		String sql = "select * from project_base  ";
		DaoParam param = _dao.createParam(sql);
		
		return _dao.query(param);
	}
}
